import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia';



import App from './App.vue'
import router from './router'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
const pinia = createPinia();

import axios from 'axios'
//读Api接口
const api1=axios.create({
  baseURL:'http://localhost:5292',
  timeout:10000
})
//写Api接口
const api2=axios.create({
  baseURL:'http://localhost:5018',
  timeout:10000
})
// 添加JWT token信息
//api1.defaults.headers.common["Authorization"] = "Bearer " + window.localStorage.getItem("token");
//api2.defaults.headers.common["Authorization"] = "Bearer " + window.localStorage.getItem("token");
//请求拦截器 客服端每次请求时，自动带上token
// 请求拦截器
import { useUserStore } from '@/stores/user'; // 导入 useUserStore

api1.interceptors.request.use(config => {
  const token=localStorage.getItem('Token');
  console.log(token);  // 替换为你的 JWT
  if (token) {
    config.headers.Authorization= `Bearer ${token}`;
  }
  return config;
}, error => {
  return Promise.reject(error);
});


export {api1,api2}




const app = createApp(App)

app.use(ElementPlus, {
    locale: zhCn,
  })

//app.use(createPinia())
app.use(router)
app.use(pinia);
const userStore= useUserStore()
app.mount('#app')
